package com.xmy.cultivate.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.xmy.cultivate.service.IRolePermissionService;
import com.xmy.cultivate.util.Code;
import com.xmy.cultivate.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author min
 * @since 2022-09-25
 */
@RestController
@RequestMapping("/api/rolePermission")
public class RolePermissionController {
    @Autowired
    IRolePermissionService iRolePermissionService;

    @ApiOperation("通过角色查询权限")
    @GetMapping("")
    public Result getRolePermissionAllByStaffId(@RequestParam(value = "roleId", required = false) String roleId) {
        if (StringUtils.isBlank(roleId)) {
            return new Result(Code.GET_OK, null, Code.GET_OK_MSG);
        }
        // 查询财务权限
        List<Long> staffPermissionList = iRolePermissionService.getRolePermissionByRoleId(roleId);
        // 查询教务权限
        List<Long> rolePermissionList = iRolePermissionService.getMobileRolePermissionByRoleId(roleId);

        HashMap hashMap = new HashMap<>();
        hashMap.put("staffPermissionList",staffPermissionList);
        hashMap.put("rolePermissionList",rolePermissionList);

        return new Result(Code.GET_OK, hashMap, Code.GET_OK_MSG);
    }

}
